package com.yc.jpyy.drivertrain.service.impl;


import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.yc.jpyy.base.util.PageBean;
import com.yc.jpyy.drivertrain.dao.DriverTrainDao;
import com.yc.jpyy.drivertrain.service.DriverTrainService;

@Service
public class DriverTrainServiceImpl  implements DriverTrainService {
    
	@Autowired
	private DriverTrainDao driverDao;

	

	@Override
	public int addDriverTrainServer(Map<String, Object> paramsMap) throws DataAccessException {
		int ret = driverDao.addDriverTrainDao(paramsMap);
		return ret;
	}

	@Override
	public int updateDriverTrainServer(Map<String, Object> paramsMap) throws DataAccessException {
		int ret = driverDao.updateDriverTrainDao(paramsMap);
		return ret;
		
	}

	@Override
	public int delDriverTrainServer(Map<String, Object> paramsMap) throws DataAccessException {
		int ret = driverDao.delDriverTrainDao(paramsMap);
		return ret;
	}

	@Override
	public Map<String, Object> findDriverTrainByIDServer(Map<String, Object> paramsMap) throws DataAccessException {
	     return driverDao.findDriverTrainByID(paramsMap);
	}

	

	@Override
	public PageBean findDriverTrainServer(Map<String, Object> paramsMap) throws DataAccessException {
		int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
		int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
		paramsMap.put("pagestart", (pagenum-1) * pagesize);
		String unitid = Optional.ofNullable(paramsMap.get("unitid")).orElse("").toString();
		paramsMap.put("unitid", unitid.equals("")?"":unitid.split(","));
		List<Map<String, Object>> list = driverDao.findDriverTrainDao(paramsMap);
		PageBean pageBean = new PageBean();
		pageBean.setList(list);
		// 每页几条数据，默认20条
		pageBean.setPageSize(pagesize);
		// 得到数据库中的条数
		pageBean.setAllRow(this.findDriverTrainServerCount(paramsMap));
		// 当前第几页，默认第一页
		pageBean.setCurrentPage(pagenum);
		// 得到一共几页
		pageBean.setTotalPage(pageBean.getTotalPage());
		// 模仿百度分页，只显示10条数据
		pageBean.paginationTool(pagenum, pageBean.getTotalPage());
		return pageBean;
	}

	@Override
	public int findDriverTrainServerCount(Map<String, Object> paramsMap) throws DataAccessException {
		return driverDao.findDriverTrainDaoCount(paramsMap);
	}

	@Override
	public int delforUpdateDriverTrainServer(Map<String, Object> paramsMap) throws DataAccessException {
		int i = driverDao.delforUpdateDriverTrainDao(paramsMap);
		if(i < 0){
			return  i;
		}else{
			return driverDao.UpdateStudentBaseInfo(paramsMap);
		}
	}

	@Override
	public int addTrainToDriver(Map<String, Object> paramsMap) throws DataAccessException {
		// TODO Auto-generated method stub
		return driverDao.addTrainToDriver(paramsMap);
		
	}

	
	

	
}
